package app.common.utils.cjt.vo;

import app.common.utils.cjt.ao.OtherReceiveCreateAo;
import app.common.utils.cjt.ao.ToOtherReceiveCreateAoDto;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 其他入库单查询响应对象
 * @author feizns
 * @since 2023/04/04
 */
@NoArgsConstructor
@Data
public class WmsStockinOtherQueryWithDetailVo {

    /**
     * total_count
     */
    private Integer total_count;
    /**
     * order
     */
    private List<Order> order;

    /**
     * Order
     */
    @NoArgsConstructor
    @Data
    public static class Order implements ToOtherReceiveCreateAoDto {
        /**
         * order_no
         */
        private String order_no;
        /**
         * created_time
         */
        private Long created_time;
        /**
         * reason
         */
        private String reason;
        /**
         * stockin_id
         */
        private Integer stockin_id;
        /**
         * total_cost
         */
        private Double total_cost;
        /**
         * total_price
         */
        private Double total_price;
        /**
         * detail_list
         */
        private List<DetailList> detail_list;
        /**
         * remark
         */
        private String remark;
        /**
         * goods_count
         */
        private Integer goods_count;
        /**
         * src_order_no
         */
        private String src_order_no;
        /**
         * operator_name
         */
        private String operator_name;
        /**
         * warehouse_name
         */
        private String warehouse_name;
        /**
         * warehouse_no
         */
        private String warehouse_no;
        /**
         * logistics_type
         */
        private Integer logistics_type;
        /**
         * stockin_time
         */
        private Long stockin_time;
        /**
         * status
         */
        private Integer status;
        /**
         * check_time
         */
        private Long check_time;

        public OtherReceiveCreateAo.Dto toOtherReceiveCreateAo() {
            OtherReceiveCreateAo.Dto dto = new OtherReceiveCreateAo.Dto();
            dto.setCode(this.getOrder_no());
            dto.setExternalCode(this.getOrder_no());
//            dto.setMemo("编号：[" + this.getOrder_no() + "] 备注:[" + this.getRemark() + "] 类型：[其他入库单]");
            dto.setMemo("来源：[旺店通] 表单；[其他入库单] 编号：[" + this.getOrder_no() + "] 备注:[" + this.getRemark() + "]");
            dto.setRdStyle(new OtherReceiveCreateAo.Dto.RdStyle("113"));
            dto.setBusiType(new OtherReceiveCreateAo.Dto.BusiType("13"));
            dto.setVoucherType(new OtherReceiveCreateAo.Dto.VoucherType("ST1004"));
            dto.setVoucherDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date(this.getStockin_time())));;
            dto.setWarehouse(new OtherReceiveCreateAo.Dto.Warehouse(this.getWarehouse_no()));
            List<OtherReceiveCreateAo.Dto.RDRecordDetails> details = this.detail_list
                    .stream()
                    .map(DetailList::toRDRecordDetails)
                    .collect(Collectors.toList());
            dto.setRDRecordDetails(details);
            return dto;
        }

        /**
         * DetailList
         */
        @NoArgsConstructor
        @Data
        public static class DetailList {
            /**
             * stockin_id
             */
            private Integer stockin_id;
            /**
             * goods_count
             */
            private Integer goods_count;
            /**
             * total_cost
             */
            private Double total_cost;
            /**
             * defect
             */
            private Boolean defect;
            /**
             * remark
             */
            private String remark;
            /**
             * right_num
             */
            private Integer right_num;
            /**
             * goods_unit
             */
            private String goods_unit;
            /**
             * expire_date
             */
            private String expire_date;
            /**
             * rec_id
             */
            private Integer rec_id;
            /**
             * production_date
             */
            private String production_date;
            /**
             * goods_name
             */
            private String goods_name;
            /**
             * goods_no
             */
            private String goods_no;
            /**
             * spec_no
             */
            private String spec_no;
            /**
             * prop2
             */
            private String prop2;
            /**
             * spec_name
             */
            private String spec_name;
            /**
             * spec_code
             */
            private String spec_code;
            /**
             * brand_no
             */
            private String brand_no;
            /**
             * brand_name
             */
            private String brand_name;
            /**
             * checked_cost_price
             */
            private Double checked_cost_price;

            public OtherReceiveCreateAo.Dto.RDRecordDetails toRDRecordDetails() {
                OtherReceiveCreateAo.Dto.RDRecordDetails details = new OtherReceiveCreateAo.Dto.RDRecordDetails();
                details.setInventory(new OtherReceiveCreateAo.Dto.RDRecordDetails.Inventory(this.getSpec_no()));
                details.setBaseQuantity(BigDecimal.valueOf(Double.valueOf(this.getGoods_count())));
                details.setPrice(BigDecimal.valueOf(this.getChecked_cost_price()));
                details.setAmount(BigDecimal.valueOf(this.getTotal_cost()));
                return details;
            }

        }
    }

}
